<template>
  <div class="caseComp">
    <div class="caseCompTitle">编辑投诉类型</div>
    <div class="caseCompList">
      <el-form
        label-width="120px"
        :model="initInfo"
        :rules="rules"
        ref="formData"
      >
        <el-form-item label="是否重复诉求" prop="isRepeat">
          <el-input
            v-model="initInfo.isRepeat"
            clearable=""
            placeholder="请输入"
            class="caseCompTitleInput"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="caseCompBtn">
      <el-button
        type="primary"
        v-sdc
        :loading="isLoading"
        class="commonBut saveBtn"
        @click="save"
        >保存</el-button
      >
      <el-button type="default" v-sdc class="commonBut" @click="finish"
        >取消</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  name: 'caseType',
  props: {
    childData: {
      type: Object,
      required: true,
      default() {
        return {}
      },
    },
  },
  data() {
    var validateisRepeat = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入是否重复诉求'))
      } else if (!['是', '否'].includes(value)) {
        callback(new Error('仅可填入是或否!'))
      } else {
        callback()
      }
    }
    return {
      isLoading: false,
      initInfo: {
        id: '',
        isRepeat: '否',
      },
      rules: {
        isRepeat: [
          { required: true, validator: validateisRepeat, trigger: 'blur' },
        ],
      },
    }
  },
  mounted() {
    this.initInfo = JSON.parse(JSON.stringify(this.childData))
  },

  methods: {
    save() {
      let params = this.initInfo
      delete params.createTime
      delete params.isDeleted
      delete params.effectiveStartDate
      delete params.effectiveEndDate
      delete params.creatorId
      delete params.updateTime
      delete params.updaterId
      this.$refs.formData.validate((valid) => {
        if (valid) {
          this.axios
            .post('api-r/complaint/registration/edit', params)
            .then((res) => {
              if (!res.data.hasError) {
                this.$message({
                  type: 'success',
                  message: '修改成功',
                })
                this.isLoading = false
                this.finish(1)
              } else {
                this.$message({
                  type: 'warning',
                  message: res.data.errorMsg || '修改失败',
                })
                this.isLoading = false
              }
            })
        }
      })
    },
    finish(index) {
      this.$emit('callback', { success: index == 1 ? true : false })
    },
  },
}
</script>
<style lang="less" scoped>
.caseComp {
  border: 1px solid #dcdfe6;
  background-color: #f8f9fb;
  padding: 15px;
  &Title {
    color: #009588;
    font-size: 14px;
    line-height: 30px;
    margin-bottom: 12px;
  }
  &List {
    line-height: 36px;
    height: 36px;
    font-size: 14px;
    color: #444;
    margin-bottom: 12px;
    &Title {
      width: 85px;
    }
    .input {
      width: calc(100% - 170px);
    }
  }
  &Btn {
    text-align: center;
    margin: 24px 0 10px;
    .el-button {
      width: 120px;
    }
  }
  /deep/ .el-radio__input.is-checked + .el-radio__label {
    color: #009588 !important;
  }
  /deep/.el-radio__input.is-checked .el-radio__inner {
    background: #009588 !important;
    border-color: #009588 !important;
  }
}
</style>
